package com.example.second_home_work

import android.os.Bundle
import android.widget.Button
import android.widget.LinearLayout
import android.widget.Spinner
import android.widget.TextView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class MainActivity : AppCompatActivity() {
    private var textViewCount = 0
    val expert = ProgramExpert()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }

        val linearLayout: LinearLayout = findViewById(R.id.linearLayout)

        val addButton: Button = findViewById(R.id.button)

        addButton.setOnClickListener {
            textViewCount++ // 每次点击时增加计数器
            val newText = "this is new TextView:$textViewCount"
            val textView = TextView(this).apply {
                this.text = newText
                layoutParams = LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.MATCH_PARENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT
                )
                setPadding(0, 16, 0, 16)
            }
            linearLayout.addView(textView)
        }

        val button: Button = findViewById(R.id.button2)

        button.setOnClickListener{
            val spinner: Spinner = findViewById(R.id.spinner)
            val textView: TextView = findViewById(R.id.textView)
            textView.text = expert.getLanguage(spinner.selectedItem.toString())
        }
    }
}